#include "HashTable.h"
/*
 *Construct the hash table
 */
template <class HashedObj>
HashTable<HashedObj>::HashTable(const HashedObj &notFound, int size)
	: ITEM_NOT_FOUND(notFound), theLists(nextPrime(size))
{
}

/*
 *Make the hash table logically empty
 */
template <class HashedObj>
void HashTable<HashedObj>::makeEmpty()
{
	for (int i = 0; i < theLists.size(); i++) {
		theLists[i].makeEmpty();	
	}
}

template <class HashedObj>
void HashTable<HashedObj>::remove(const HashedObj &x)
{
	theLists[hash(x, theLists.size())].remove(x);
}

template <class HashedObj>
const HashedObj & HashTable<HashedObj>::find(const HashedObj &x) const
{
	ListItr<HashedObj> itr;
	itr = theLists[hash(x, theLists.size())].find(x);
	return itr.isPastEnd() ? ITEM_NOT_FOUND : itr.retrieve();;
}

/*
 *Insert item x into the hash table. If the item is already present, then do nothing.
 */
template <class HashedObj>
void HashTable<HashedObj>::insert(const HashedObj &x) 
{
	List<HashedObj> &whichList = theList[hash(x, theList.size())];
	ListItr<HashedObj> itr = whichList.find(x);

	if (itr.isPastEnd())
		whichList.insert(x, whichList.zeroth());
}
